#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N=2*1e5+50;
int n;
int u,v,t;
bool vis[N];
vector<int> ans;
struct Edge{
    int u,v,t,next;
}edge[N];
int head[N];
int cnt;
void init(){
    cnt=0;
    memset(head,-1,sizeof(head));
}
void addEdge(int u,int v,int t){
    edge[cnt]=Edge{u,v,t,head[u]};
    head[u]=cnt++;
    edge[cnt]=Edge{v,u,t,head[v]};
    head[v]=cnt++;
}
//is: u_fa--u这条边是否标记
int dfs(int u,bool is){
    //printf("%d %d\n",u,is);
    vis[u]=true;
    int sum=0;
    for(int i=head[u];i!=-1;i=edge[i].next){
        int v=edge[i].v;
        int t=edge[i].t;
        if(vis[v]){
            continue;
        }
        if(t==2){
            sum+=dfs(v,true);
        }
        else{
            sum+=dfs(v,false);
        }
    }
    if(sum==0 && is){
        ans.push_back(u);
        return 1;
    }
    return sum;
}
int main(void){
    init();
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d%d",&u,&v,&t);
        addEdge(u,v,t);
    }
    dfs(1,false);
    int l=ans.size();
    printf("%d\n",l);
    if(l>0){
        for(int i=0;i<l-1;i++){
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[l-1]);
    }
    return 0;
}